/*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
package nc.ui.uapbd.cldy.handler;

import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillItem;
import nc.ui.pub.bill.BillModel;
import nc.ui.pub.bill.BillScrollPane;
import nc.ui.pubapp.uif2app.event.card.CardBodyAfterEditEvent;
import nc.ui.pubapp.uif2app.event.card.CardBodyBeforeEditEvent;
import nc.vo.bd.material.marbasclass.MarBasClassVO;

public class MaterialHandler {
	public void afterEdit(CardBodyAfterEditEvent e) {
		BillCardPanel panel = e.getBillCardPanel();
		BillScrollPane scrollPane = panel.getBodyPanel();
		//panel.stopEditing();
		BillModel billModel = panel.getBillModel();
		int max = -1;
		for(int i = 0;i<billModel.getRowCount();i++){
			if(Integer.valueOf((String)billModel.getValueAt(i,3))>max){
				max = Integer.valueOf((String)billModel.getValueAt(i,3));
			}
		}
		UIRefPane refPane = (UIRefPane) panel.getBodyItem(e.getKey())
				.getComponent();
		String[] pks = refPane.getRefPKs();
		String[] names = refPane.getRefNames();
		int row = e.getRow();
		billModel.setValueAt(pks[0],row,4);
		billModel.setValueAt(names[0],row,5);
		int index = 0;
		for(int i = 1;i<pks.length;i++){
			scrollPane.addLine();
			index = billModel.getRowCount() - 1;
			String lineNo = String.valueOf(max+10);
			max = max + 10;
			billModel.setValueAt(lineNo,index,3);
			billModel.setValueAt(pks[i],index,4);
			billModel.setValueAt(names[i],index,5);
		}
		//System.out.println(pks.toString());
	}

	public void beforeEdit(CardBodyBeforeEditEvent e) {
		BillCardPanel panel = e.getBillCardPanel();
		UIRefPane refPane = (UIRefPane) panel.getBodyItem(e.getKey())
				.getComponent();
		refPane.setMultiSelectedEnabled(true);
		e.setReturnValue(Boolean.TRUE);
	}
}